module ApplicationHelper
  
  BODY_IDS = {
    :site_index     => "home",
    :users_new      => "signup",
    :users_create   => "signup",
    :users_home     => "userhome",
    :events_new     => "events",
    :events_update  => "events",
    :events_invite  => "events",
    :events_gmail   => "events",
    :events_tvienes_contacts   => "events",
    :events_copiagenda  => "events",
    :events_show    => "eventshow"
  }
  
  # construimos un body_id para la página
  def get_body_id
    controller_action = "#{params[:controller]}_#{params[:action]}"
    @body_id = BODY_IDS[controller_action.to_sym]
    @body_id ||= controller_action
  end
  
  # mensajes de error para flash
  def get_flash
    flashed = ""
    flashed += "<div id='alert'>#{flash[:alert]}</div>" unless flash[:alert].blank?
    flashed += "<div id='notice'>#{flash[:notice]}</div>" unless flash[:notice].blank?
    flashed
  end
  
  def get_menu
    menu = "<div id='main_menu'>"
    if logged_in?
      menu += "<span>hola <strong>#{strip_tags(current_user.public_name)}</strong></span>"
      menu += link_to '<strong>Crea un nuevo evento</strong>', {:action => 'new', :controller => 'events'}, {:class => 'yellow'}
      menu += link_to 'Tu home', user_home_url(current_user.login)
      menu += link_to 'Tus datos', user_options_url
      menu += link_to 'Salir', logout_url, {:id => 'logout'}
    else
      menu += link_to 'Registro', signup_url
      menu += link_to 'Login', login_url, {:id => 'login'}
      menu += link_to 'Acerca de', {}
    end
    menu += "</div>"
    
    menu
  end
  
  def get_invitation
    unless session["invitation"].nil? || params[:controller] == "sessions"
      @invitation = Invitation.find_by_code(session["invitation"])
      "<div class='greendialog clearfix' id='pending_invitation'>
        <div class='cont clearfix'>
          <div class='actions'>
            #{if logged_in?
              "#{link_to 'Me apunto :)', {:controller => "events", :action => "accept_invitation", :code => session["invitation"], :accept => "true"}, :class => 'accept'}
              #{link_to 'No puedo ir :(', {:controller => "events", :action => "accept_invitation", :code => session["invitation"], :accept => "false"}, :class => 'deny'}"
            else
              "#{link_to 'Haz Login', login_url, :class => 'accept'}
              #{link_to_remote 'Ahora no', {:url => {:controller => "events", :action => "forget_invitation"}}, :class => 'deny'}"
            end
            }
          </div>
          <strong>#{link_to image_tag(@invitation.event.user.avatar.public_filename(:thumb)), {}, :class => 'avatar' }</strong>
          #{link_to @invitation.event.user.public_name, {}} te ha invitado a #{link_to @invitation.event.title, event_url(@invitation.event)}.<br/>
          Ahora espera que aceptes la invitación o que le digas que no puedes ir.

        </div>
      </div>"
    end
  end
  
  def get_activation
    unless session["activation"].nil?
      session["activation"] = nil 
      "<div class='greendialog clearfix'>
        <div class='cont clearfix'>
          Pues <strong>ya está</strong>!! Acabamos de enviarte un correo para activar tu cuenta!.
        </div>
      </div>"
    end
  end
  
  
end
